package cn.anecansaitin.firecrafting.client.crafting;

import cn.anecansaitin.firecrafting.api.common.crafting.IFireRecipe;
import cn.anecansaitin.firecrafting.api.client.crafting.IJEIRecipeRender;
import cn.anecansaitin.firecrafting.client.util.RenderHelper;
import cn.anecansaitin.firecrafting.common.crafting.FireBlockRecipe;
import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.network.chat.Component;
import net.minecraft.world.level.block.Block;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class FireBlockRecipeRender implements IJEIRecipeRender {
    //这个类只需要一个就可以了，因此将构造函数设为private并提供一个静态实现。
    public static final FireBlockRecipeRender INSTANCE = new FireBlockRecipeRender();

    private FireBlockRecipeRender() {
    }

    @Override
    public void drawBeforeFire(IFireRecipe recipe, PoseStack stack, double mouseX, double mouseY) {
        //判断为FireBlockRecipe
        if (recipe instanceof FireBlockRecipe) {
            //获取产物
            Map<Integer, Block> outputs = ((FireBlockRecipe) recipe).getOutputs();
            //遍历渲染每一个方块
            for (Map.Entry<Integer, Block> entry : outputs.entrySet()) {
                //按照位置来渲染
                switch (entry.getKey()) {
                    case -1 -> RenderHelper.renderGUIBlock(entry.getValue(), stack, 144, 41);
                    case 0 -> RenderHelper.renderGUIBlock(entry.getValue(), stack, 144, 33, 5);
                    case 1 -> RenderHelper.renderGUIBlock(entry.getValue(), stack, 144, 25, 10);
                }
            }
        }
    }

    @Override
    public List<Component> getTooltip(IFireRecipe recipe, double mouseX, double mouseY) {
        ArrayList<Component> list = new ArrayList<>();
        if (recipe instanceof FireBlockRecipe) {
            //获取产物
            Map<Integer, Block> outputs = ((FireBlockRecipe) recipe).getOutputs();
            //根据鼠标位置返回对应方块名称
            if (mouseX >= 144 && mouseX < 160 && mouseY >= 25) {
                if (mouseY < 39 && outputs.containsKey(1)) {
                    list.add(outputs.get(1).getName());
                } else if (mouseY < 49 && outputs.containsKey(0)) {
                    list.add(outputs.get(0).getName());
                } else if (mouseY < 58 && outputs.containsKey(-1)) {
                    list.add(outputs.get(-1).getName());
                }
            }
        }
        return list;
    }
}
